import { ModalForm } from '@ant-design/pro-components';
import type { FormInstance } from 'antd';
import { Collapse, Checkbox, message } from 'antd';
import { useRef } from 'react';
import CollapsePanel from 'antd/lib/collapse/CollapsePanel';
import { useState } from 'react';
import { useModel } from 'umi';
import type { CheckboxChangeEvent, CheckboxOptionType } from 'antd/lib/checkbox';
import styles from '../style.less';
import { CaretRightFilled } from '@ant-design/icons';
import { getAuthById, updateAuthById } from '../service';
import { Auths, mapAuthToLabel } from '@/utils/types.d';
import type { AuthType } from '../types';
import { EMPTYAUTH } from '../types';

interface AuthSettingProps {
  authId: string;
  ownerName: string;
}
interface AuthOptions {
  label: string;
  value: string;
  disable?: boolean;
}
const CheckboxGroup = Checkbox.Group;

export default (props: AuthSettingProps) => {
  const { initialState } = useModel('@@initialState');
  const currUser = initialState?.currentUser;
  const CURRAUTH: AuthType = currUser?.auth || EMPTYAUTH;
  // TODO: 扩展权限

  const OPER_SYSTEMUSER = CURRAUTH.systemUser || [];
  const OPER_SYSRECORD = CURRAUTH.sysRecord || [];
  const OPER_SENSORDEVICE = CURRAUTH.sensorDevice || [];
  const OPER_PATROLDEVICE = CURRAUTH.patrolDevice || [];
  const OPER_PARKINGLOT = CURRAUTH.parkinglot || [];
  const OPER_PARKINGSPOT = CURRAUTH.parkingspot || [];
  const OPER_BATCHTASK = CURRAUTH.batchTask || [];
  const OPER_CHARGERULE = CURRAUTH.chargeRule || [];
  const OPER_PARKINGRECORD = CURRAUTH.parkingRecord || [];
  const OPER_PARKINGORDER = CURRAUTH.parkingOrder || [];
  const OPER_TOLLCOLLECTOR = CURRAUTH.tollCollector || [];
  const OPER_MEMBER = CURRAUTH.member || [];
  const OPER_WECHATUSER = CURRAUTH.wechatUser || [];
  const OPER_ARREARSRECOVERY = CURRAUTH.arrearsRecovery || [];
  const OPER_REVENUE = CURRAUTH.revenue || [];

  const { authId, ownerName } = props;
  const systemSettingRef = useRef<FormInstance>();
  // systemUser
  const [systemUserIntermin, setSystemUserIntermin] = useState<boolean>(true);
  const [systemUserList, setSystemUserList] = useState<string[]>([Auths.READ]);
  const [systemUserEnable, setSystemUserEnable] = useState<boolean>(false);
  const [systemUserCheckAll, setSystemUserCheckAll] = useState<boolean>(false);
  // tollCollector
  const [tollCollectorIntermin, setTollCollectorIntermin] = useState<boolean>(true);
  const [tollCollectorList, setTollCollectorList] = useState<string[]>([Auths.READ]);
  const [tollCollectorEnable, setTollCollectorEnable] = useState<boolean>(false);
  const [tollCollectorCheckAll, setTollCollectorCheckAll] = useState<boolean>(false);
  // sysRecord
  const [sysRecordIntermin, setSysRecordIntermin] = useState<boolean>(true);
  const [sysRecordList, setSysRecordList] = useState<string[]>([Auths.READ]);
  const [sysRecordEnable, setSysRecordEnable] = useState<boolean>(false);
  const [sysRecordCheckAll, setSysRecordCheckAll] = useState<boolean>(false);
  // sensor
  const [sensorDeviceIntermin, setSensorDeviceIntermin] = useState<boolean>(true);
  const [sensorDeviceList, setSensorDeviceList] = useState<string[]>([Auths.READ]);
  const [sensorDeviceEnable, setSensorDeviceEnable] = useState<boolean>(false);
  const [sensorDeviceCheckAll, setSensorDeviceCheckAll] = useState<boolean>(false);
  // patrol
  const [patrolDeviceIntermin, setPatrolDeviceIntermin] = useState<boolean>(true);
  const [patrolDeviceList, setPatrolDeviceList] = useState<string[]>([Auths.READ]);
  const [patrolDeviceEnable, setPatrolDeviceEnable] = useState<boolean>(false);
  const [patrolDeviceCheckAll, setPatrolDeviceCheckAll] = useState<boolean>(false);
  // parkinglot
  const [parkinglotIntermin, setParkinglotIntermin] = useState<boolean>(true);
  const [parkinglotList, setParkinglotList] = useState<string[]>([Auths.READ]);
  const [parkinglotEnable, setParkinglotEnable] = useState<boolean>(false);
  const [parkinglotCheckAll, setParkinglotCheckAll] = useState<boolean>(false);
  // parkingspot
  const [parkingspotIntermin, setParkingspotIntermin] = useState<boolean>(true);
  const [parkingspotList, setParkingspotList] = useState<string[]>([Auths.READ]);
  const [parkingspotEnable, setParkingspotEnable] = useState<boolean>(false);
  const [parkingspotCheckAll, setParkingspotCheckAll] = useState<boolean>(false);
  // batchTask
  const [batchTaskIntermin, setBatchTaskIntermin] = useState<boolean>(true);
  const [batchTaskList, setBatchTaskList] = useState<string[]>([Auths.READ]);
  const [batchTaskEnable, setBatchTaskEnable] = useState<boolean>(false);
  const [batchTaskCheckAll, setBatchTaskCheckAll] = useState<boolean>(false);
  // chargeRule
  const [chargeRuleIntermin, setChargeRuleIntermin] = useState<boolean>(true);
  const [chargeRuleList, setChargeRuleList] = useState<string[]>([Auths.READ]);
  const [chargeRuleEnable, setChargeRuleEnable] = useState<boolean>(false);
  const [chargeRuleCheckAll, setChargeRuleCheckAll] = useState<boolean>(false);
  // parkingRecord
  const [parkingRecordIntermin, setParkingRecordIntermin] = useState<boolean>(true);
  const [parkingRecordList, setParkingRecordList] = useState<string[]>([Auths.READ]);
  const [parkingRecordEnable, setParkingRecordEnable] = useState<boolean>(false);
  const [parkingRecordCheckAll, setParkingRecordCheckAll] = useState<boolean>(false);
  // parkingOrder
  const [parkingOrderIntermin, setParkingOrderIntermin] = useState<boolean>(true);
  const [parkingOrderList, setParkingOrderList] = useState<string[]>([Auths.READ]);
  const [parkingOrderEnable, setParkingOrderEnable] = useState<boolean>(false);
  const [parkingOrderCheckAll, setParkingOrderCheckAll] = useState<boolean>(false);
  // member
  const [memberIntermin, setMemberIntermin] = useState<boolean>(true);
  const [memberList, setMemberList] = useState<string[]>([Auths.READ]);
  const [memberEnable, setMemberEnable] = useState<boolean>(false);
  const [memberCheckAll, setMemberCheckAll] = useState<boolean>(false);
  // wechatUser
  const [wechatUserIntermin, setWechatUserIntermin] = useState<boolean>(true);
  const [wechatUserList, setWechatUserList] = useState<string[]>([Auths.READ]);
  const [wechatUserEnable, setWechatUserEnable] = useState<boolean>(false);
  const [wechatUserCheckAll, setWechatUserCheckAll] = useState<boolean>(false);
  //arrearsRecovery
  const [arrearsRecoveryIntermin, setArrearsRecoveryIntermin] = useState<boolean>(true);
  const [arrearsRecoveryList, setArrearsRecoveryList] = useState<string[]>([Auths.READ]);
  const [arrearsRecoveryEnable, setArrearsRecoveryEnable] = useState<boolean>(false);
  const [arrearsRecoveryCheckAll, setArrearsRecoveryCheckAll] = useState<boolean>(false);
  // revenue
  const [revenueIntermin, setRevenueIntermin] = useState<boolean>(true);
  const [revenueList, setRevenueList] = useState<string[]>([Auths.READ]);
  const [revenueEnable, setRevenueEnable] = useState<boolean>(false);
  const [revenueCheckAll, setRevenueCheckAll] = useState<boolean>(false);

  const systemUserAuth: AuthOptions[] = OPER_SYSTEMUSER.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : systemUserEnable,
  }));
  const tollCollectorAuth: AuthOptions[] = OPER_TOLLCOLLECTOR.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : tollCollectorEnable,
  }));
  const sysRecordAuth: AuthOptions[] = OPER_SYSRECORD.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : sysRecordEnable,
  }));
  const sensorDeviceAuth: AuthOptions[] = OPER_SENSORDEVICE.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : sensorDeviceEnable,
  }));
  const patrolDeviceAuth: AuthOptions[] = OPER_PATROLDEVICE.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : patrolDeviceEnable,
  }));
  const parkinglotAuth: AuthOptions[] = OPER_PARKINGLOT.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : parkinglotEnable,
  }));
  const parkingspotAuth: AuthOptions[] = OPER_PARKINGSPOT.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : parkingspotEnable,
  }));
  const batchTaskAuth: AuthOptions[] = OPER_BATCHTASK.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : batchTaskEnable,
  }));
  const chargeRuleAuth: AuthOptions[] = OPER_CHARGERULE.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : chargeRuleEnable,
  }));
  const parkingRecordAuth: AuthOptions[] = OPER_PARKINGRECORD.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : parkingRecordEnable,
  }));
  const parkingOrderAuth: AuthOptions[] = OPER_PARKINGORDER.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : parkingOrderEnable,
  }));
  const memberAuth: AuthOptions[] = OPER_MEMBER.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : memberEnable,
  }));
  const wechatUserAuth: AuthOptions[] = OPER_WECHATUSER.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : wechatUserEnable,
  }));
  const arrearsRecoveryAuth: AuthOptions[] = OPER_ARREARSRECOVERY.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : arrearsRecoveryEnable,
  }));
  const revenueAuth: AuthOptions[] = OPER_REVENUE.map((item) => ({
    label: mapAuthToLabel(item),
    value: item,
    disabled: item === Auths.READ ? false : revenueEnable,
  }));

  const onChange = (
    list: any[],
    setList: (arg0: string[]) => void,
    setCheckAll: (arg0: boolean) => void,
    setIntermin: (arg0: boolean) => void,
    setEnable: (arg0: boolean) => void,
    authList: string | CheckboxOptionType[],
  ) => {
    let tempList = list;
    if (!list.includes(Auths.READ)) {
      message.warn({ content: '无法在无 [查看] 权限时，操作模块', key: 'read_error' });
      setEnable(true);
      tempList = [];
    } else {
      setEnable(false);
    }
    setList(tempList);
    setIntermin(!!tempList.length && tempList.length < authList.length);
    setCheckAll(tempList.length === authList.length);
  };

  const onCheckAllChange = (
    e: CheckboxChangeEvent,
    setList: (arg0: string[]) => void,
    setCheckAll: (arg0: boolean) => void,
    setIntermin: (arg0: boolean) => void,
    setEnable: (arg0: boolean) => void,
    authList: CheckboxOptionType[],
  ) => {
    setList(e.target.checked ? authList.map((item: { value: any }) => item.value) : []);
    setIntermin(false);
    setEnable(!e.target.checked);
    setCheckAll(e.target.checked);
  };
  return (
    <ModalForm
      formRef={systemSettingRef}
      width={700}
      modalProps={{
        destroyOnClose: true,
      }}
      title={
        <div>
          权限配置<small style={{ color: '#bbb' }}>（{ownerName}）</small>
        </div>
      }
      trigger={
        <a
          onClick={async () => {
            const { data } = await getAuthById(authId);
            setSensorDeviceList(data.sensorDevice);
            setPatrolDeviceList(data.patrolDevice);
            setSystemUserList(data.systemUser);
            setSysRecordList(data.sysRecord);
            setParkinglotList(data.parkinglot);
            setParkingspotList(data.parkingspot);
            setBatchTaskList(data.batchTask);
            setChargeRuleList(data.chargeRule);
            setParkingRecordList(data.parkingRecord);
            setParkingOrderList(data.parkingOrder);
            setTollCollectorList(data.tollCollector);
            setMemberList(data.member);
            setWechatUserList(data.wechatUser);
            setArrearsRecoveryList(data.arrearsRecovery);
            setRevenueList(data.revenue);
            // 用户
            if (data.systemUser.length === 0) {
              setSystemUserIntermin(false);
              setSystemUserEnable(true);
            } else if (data.systemUser.length === systemUserAuth.length) {
              setSystemUserIntermin(false);
              setSystemUserCheckAll(true);
            }
            // 收费人员
            if (data.tollCollector.length === 0) {
              setTollCollectorIntermin(false);
              setTollCollectorEnable(true);
            } else if (data.tollCollector.length === tollCollectorAuth.length) {
              setTollCollectorIntermin(false);
              setTollCollectorCheckAll(true);
            }
            // 系统日志
            if (data.sysRecord.length === 0) {
              setSysRecordIntermin(false);
              setSysRecordEnable(true);
            } else if (data.sysRecord.length === sysRecordAuth.length) {
              setSysRecordIntermin(false);
              setSysRecordCheckAll(true);
            }
            // 地磁设备
            if (data.sensorDevice.length === 0) {
              setSensorDeviceIntermin(false);
              setSensorDeviceEnable(true);
            } else if (data.sensorDevice.length === sensorDeviceAuth.length) {
              setSensorDeviceIntermin(false);
              setSensorDeviceCheckAll(true);
            }
            // 巡检设备
            if (data.patrolDevice.length === 0) {
              setPatrolDeviceIntermin(false);
              setPatrolDeviceEnable(true);
            } else if (data.patrolDevice.length === patrolDeviceAuth.length) {
              setPatrolDeviceIntermin(false);
              setPatrolDeviceCheckAll(true);
            }
            // 路段
            if (data.parkinglot.length === 0) {
              setParkinglotIntermin(false);
              setParkinglotEnable(true);
            } else if (data.parkinglot.length === parkinglotAuth.length) {
              setParkinglotIntermin(false);
              setParkinglotCheckAll(true);
            }
            // 泊位
            if (data.parkingspot.length === 0) {
              setParkingspotIntermin(false);
              setParkingspotEnable(true);
            } else if (data.parkingspot.length === parkingspotAuth.length) {
              setParkingspotIntermin(false);
              setParkingspotCheckAll(true);
            }
            // 批量任务
            if (data.batchTask.length === 0) {
              setBatchTaskIntermin(false);
              setBatchTaskEnable(true);
            } else if (data.batchTask.length === batchTaskAuth.length) {
              setBatchTaskIntermin(false);
              setBatchTaskCheckAll(true);
            }
            // 收费规则
            if (data.chargeRule.length === 0) {
              setChargeRuleIntermin(false);
              setChargeRuleEnable(true);
            } else if (data.chargeRule.length === chargeRuleAuth.length) {
              setChargeRuleIntermin(false);
              setChargeRuleCheckAll(true);
            }
            // 停车记录
            if (data.parkingRecord.length === 0) {
              setParkingRecordIntermin(false);
              setParkingRecordEnable(true);
            } else if (data.parkingRecord.length === parkingRecordAuth.length) {
              setParkingRecordIntermin(false);
              setParkingRecordCheckAll(true);
            }
            // 停车订单
            if (data.parkingOrder.length === 0) {
              setParkingOrderIntermin(false);
              setParkingOrderEnable(true);
            } else if (data.parkingOrder.length === parkingOrderAuth.length) {
              setParkingOrderIntermin(false);
              setParkingOrderCheckAll(true);
            }
            // 会员卡
            if (data.member.length === 0) {
              setMemberIntermin(false);
              setMemberEnable(true);
            } else if (data.member.length === memberAuth.length) {
              setMemberIntermin(false);
              setMemberCheckAll(true);
            }
            // 微信小程序
            if (data.wechatUser.length === 0) {
              setWechatUserIntermin(false);
              setWechatUserEnable(true);
            } else if (data.wechatUser.length === wechatUserAuth.length) {
              setWechatUserIntermin(false);
              setWechatUserCheckAll(true);
            }
            // 欠费追缴
            if (data.arrearsRecovery.length === 0) {
              setArrearsRecoveryIntermin(false);
              setArrearsRecoveryEnable(true);
            } else if (data.arrearsRecovery.length === arrearsRecoveryAuth.length) {
              setArrearsRecoveryIntermin(false);
              setArrearsRecoveryCheckAll(true);
            }

            // 营收统计
            if (data.revenue.length === 0) {
              setRevenueIntermin(false);
              setRevenueEnable(true);
            } else if (data.revenue.length === revenueAuth.length) {
              setRevenueIntermin(false);
              setRevenueCheckAll(true);
            }
          }}
        >
          权限配置
        </a>
      }
      onFinish={async () => {
        const res = await updateAuthById(authId, {
          systemUser: systemUserList,
          sysRecord: sysRecordList,
          sensorDevice: sensorDeviceList,
          patrolDevice: patrolDeviceList,
          parkinglot: parkinglotList,
          parkingspot: parkingspotList,
          batchTask: batchTaskList,
          chargeRule: chargeRuleList,
          parkingRecord: parkingRecordList,
          parkingOrder: parkingOrderList,
          tollCollector: tollCollectorList,
          member: memberList,
          wechatUser: wechatUserList,
          arrearsRecovery: arrearsRecoveryList,
          revenue: revenueList,
        });
        if (res.success) {
          message.success({ content: res.message, key: 'auth_msg' });
          return true;
        }
        message.error({ content: res.message, key: 'auth_msg' });
        return false;
      }}
    >
      <Collapse
        bordered={false}
        className={styles.mycollapse}
        expandIcon={({ isActive }) => <CaretRightFilled rotate={isActive ? 90 : 0} />}
        defaultActiveKey={[]}
        accordion
      >
        {(OPER_PARKINGLOT.length || OPER_PARKINGSPOT.length || OPER_PARKINGRECORD.length) && (
          <CollapsePanel header="停车管理" className={styles.mypanel} key="parkingConfig">
            <Collapse accordion bordered={false} ghost defaultActiveKey={[]}>
              {OPER_PARKINGLOT.length && (
                <CollapsePanel
                  key="parkinglot"
                  header={
                    <Checkbox
                      indeterminate={parkinglotIntermin}
                      onChange={(e) => {
                        onCheckAllChange(
                          e,
                          setParkinglotList,
                          setParkinglotCheckAll,
                          setParkinglotIntermin,
                          setParkinglotEnable,
                          parkinglotAuth,
                        );
                      }}
                      checked={parkinglotCheckAll}
                      onClick={(e) => e.stopPropagation()}
                    >
                      路段管理
                    </Checkbox>
                  }
                >
                  <CheckboxGroup
                    options={parkinglotAuth}
                    name="parkinglot"
                    value={parkinglotList}
                    onChange={(list) => {
                      onChange(
                        list,
                        setParkinglotList,
                        setParkinglotCheckAll,
                        setParkinglotIntermin,
                        setParkinglotEnable,
                        parkinglotAuth,
                      );
                    }}
                  />
                </CollapsePanel>
              )}
              {OPER_PARKINGSPOT.length && (
                <CollapsePanel
                  key="parkingspot"
                  header={
                    <Checkbox
                      indeterminate={parkingspotIntermin}
                      onChange={(e) => {
                        onCheckAllChange(
                          e,
                          setParkingspotList,
                          setParkingspotCheckAll,
                          setParkingspotIntermin,
                          setParkingspotEnable,
                          parkingspotAuth,
                        );
                      }}
                      checked={parkingspotCheckAll}
                      onClick={(e) => e.stopPropagation()}
                    >
                      泊位管理
                    </Checkbox>
                  }
                >
                  <CheckboxGroup
                    options={parkingspotAuth}
                    name="parkingspot"
                    value={parkingspotList}
                    onChange={(list) => {
                      onChange(
                        list,
                        setParkingspotList,
                        setParkingspotCheckAll,
                        setParkingspotIntermin,
                        setParkingspotEnable,
                        parkingspotAuth,
                      );
                    }}
                  />
                </CollapsePanel>
              )}
              {OPER_PARKINGRECORD.length && (
                <CollapsePanel
                  key="parkingRecord"
                  header={
                    <Checkbox
                      indeterminate={parkingRecordIntermin}
                      onChange={(e) => {
                        onCheckAllChange(
                          e,
                          setParkingRecordList,
                          setParkingRecordCheckAll,
                          setParkingRecordIntermin,
                          setParkingRecordEnable,
                          parkingRecordAuth,
                        );
                      }}
                      checked={parkingRecordCheckAll}
                      onClick={(e) => e.stopPropagation()}
                    >
                      停车记录
                    </Checkbox>
                  }
                >
                  <CheckboxGroup
                    options={parkingRecordAuth}
                    name="parkingRecord"
                    value={parkingRecordList}
                    onChange={(list) => {
                      onChange(
                        list,
                        setParkingRecordList,
                        setParkingRecordCheckAll,
                        setParkingRecordIntermin,
                        setParkingRecordEnable,
                        parkingRecordAuth,
                      );
                    }}
                  />
                </CollapsePanel>
              )}
            </Collapse>
          </CollapsePanel>
        )}
        {(OPER_SENSORDEVICE.length || OPER_PATROLDEVICE.length) && (
          <CollapsePanel header="设备管理" className={styles.mypanel} key="deviceConfig">
            <Collapse accordion bordered={false} ghost defaultActiveKey={[]}>
              {OPER_SENSORDEVICE.length && (
                <CollapsePanel
                  key="sensorDevice"
                  header={
                    <Checkbox
                      indeterminate={sensorDeviceIntermin}
                      onChange={(e) => {
                        onCheckAllChange(
                          e,
                          setSensorDeviceList,
                          setSensorDeviceCheckAll,
                          setSensorDeviceIntermin,
                          setSensorDeviceEnable,
                          sensorDeviceAuth,
                        );
                      }}
                      checked={sensorDeviceCheckAll}
                      onClick={(e) => e.stopPropagation()}
                    >
                      地磁设备
                    </Checkbox>
                  }
                >
                  <CheckboxGroup
                    options={sensorDeviceAuth}
                    name="sensorDevice"
                    value={sensorDeviceList}
                    onChange={(list) => {
                      onChange(
                        list,
                        setSensorDeviceList,
                        setSensorDeviceCheckAll,
                        setSensorDeviceIntermin,
                        setSensorDeviceEnable,
                        sensorDeviceAuth,
                      );
                    }}
                  />
                </CollapsePanel>
              )}
              {OPER_PATROLDEVICE.length && (
                <CollapsePanel
                  key="patrolDevice"
                  header={
                    <Checkbox
                      indeterminate={patrolDeviceIntermin}
                      onChange={(e) => {
                        onCheckAllChange(
                          e,
                          setPatrolDeviceList,
                          setPatrolDeviceCheckAll,
                          setPatrolDeviceIntermin,
                          setPatrolDeviceEnable,
                          patrolDeviceAuth,
                        );
                      }}
                      checked={patrolDeviceCheckAll}
                      onClick={(e) => e.stopPropagation()}
                    >
                      巡检设备
                    </Checkbox>
                  }
                >
                  <CheckboxGroup
                    options={patrolDeviceAuth}
                    name="patrolDevice"
                    value={patrolDeviceList}
                    onChange={(list) => {
                      onChange(
                        list,
                        setPatrolDeviceList,
                        setPatrolDeviceCheckAll,
                        setPatrolDeviceIntermin,
                        setPatrolDeviceEnable,
                        patrolDeviceAuth,
                      );
                    }}
                  />
                </CollapsePanel>
              )}
            </Collapse>
          </CollapsePanel>
        )}
        {OPER_REVENUE.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={revenueIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setRevenueList,
                    setRevenueCheckAll,
                    setRevenueIntermin,
                    setRevenueEnable,
                    revenueAuth,
                  );
                }}
                checked={revenueCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                营收统计
              </Checkbox>
            }
            key="revenue"
          >
            <CheckboxGroup
              options={revenueAuth}
              name="revenue"
              value={revenueList}
              onChange={(list) => {
                onChange(
                  list,
                  setRevenueList,
                  setRevenueCheckAll,
                  setRevenueIntermin,
                  setRevenueEnable,
                  revenueAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_CHARGERULE.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={chargeRuleIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setChargeRuleList,
                    setChargeRuleCheckAll,
                    setChargeRuleIntermin,
                    setChargeRuleEnable,
                    chargeRuleAuth,
                  );
                }}
                checked={chargeRuleCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                收费规则
              </Checkbox>
            }
            key="chargeRule"
          >
            <CheckboxGroup
              options={chargeRuleAuth}
              name="chargeRule"
              value={chargeRuleList}
              onChange={(list) => {
                onChange(
                  list,
                  setChargeRuleList,
                  setChargeRuleCheckAll,
                  setChargeRuleIntermin,
                  setChargeRuleEnable,
                  chargeRuleAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_PARKINGORDER.length && (
          <CollapsePanel
            key="parkingOrder"
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={parkingOrderIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setParkingOrderList,
                    setParkingOrderCheckAll,
                    setParkingOrderIntermin,
                    setParkingOrderEnable,
                    parkingOrderAuth,
                  );
                }}
                checked={parkingOrderCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                停车订单
              </Checkbox>
            }
          >
            <CheckboxGroup
              options={parkingOrderAuth}
              name="parkingOrder"
              value={parkingOrderList}
              onChange={(list) => {
                onChange(
                  list,
                  setParkingOrderList,
                  setParkingOrderCheckAll,
                  setParkingOrderIntermin,
                  setParkingOrderEnable,
                  parkingOrderAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_TOLLCOLLECTOR.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={tollCollectorIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setTollCollectorList,
                    setTollCollectorCheckAll,
                    setTollCollectorIntermin,
                    setTollCollectorEnable,
                    tollCollectorAuth,
                  );
                }}
                checked={tollCollectorCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                收费人员
              </Checkbox>
            }
            key="tollCollector"
          >
            <CheckboxGroup
              options={tollCollectorAuth}
              name="tollCollector"
              value={tollCollectorList}
              onChange={(list) => {
                onChange(
                  list,
                  setTollCollectorList,
                  setTollCollectorCheckAll,
                  setTollCollectorIntermin,
                  setTollCollectorEnable,
                  tollCollectorAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_ARREARSRECOVERY.length && (
          <CollapsePanel
            key="arrearsRecovery"
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={arrearsRecoveryIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setArrearsRecoveryList,
                    setArrearsRecoveryCheckAll,
                    setArrearsRecoveryIntermin,
                    setArrearsRecoveryEnable,
                    arrearsRecoveryAuth,
                  );
                }}
                checked={arrearsRecoveryCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                欠费追缴
              </Checkbox>
            }
          >
            <CheckboxGroup
              options={arrearsRecoveryAuth}
              name="arrearsRecovery"
              value={arrearsRecoveryList}
              onChange={(list) => {
                onChange(
                  list,
                  setArrearsRecoveryList,
                  setArrearsRecoveryCheckAll,
                  setArrearsRecoveryIntermin,
                  setArrearsRecoveryEnable,
                  arrearsRecoveryAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_MEMBER.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={memberIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setMemberList,
                    setMemberCheckAll,
                    setMemberIntermin,
                    setMemberEnable,
                    memberAuth,
                  );
                }}
                checked={memberCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                会员卡模块
              </Checkbox>
            }
            key="member"
          >
            <CheckboxGroup
              options={memberAuth}
              name="member"
              value={memberList}
              onChange={(list) => {
                onChange(
                  list,
                  setMemberList,
                  setMemberCheckAll,
                  setMemberIntermin,
                  setMemberEnable,
                  memberAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_WECHATUSER.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={wechatUserIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setWechatUserList,
                    setWechatUserCheckAll,
                    setWechatUserIntermin,
                    setWechatUserEnable,
                    wechatUserAuth,
                  );
                }}
                checked={wechatUserCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                微信用户
              </Checkbox>
            }
            key="wechatUser"
          >
            <CheckboxGroup
              options={wechatUserAuth}
              name="wechatUser"
              value={wechatUserList}
              onChange={(list) => {
                onChange(
                  list,
                  setWechatUserList,
                  setWechatUserCheckAll,
                  setWechatUserIntermin,
                  setWechatUserEnable,
                  wechatUserAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_BATCHTASK.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={batchTaskIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setBatchTaskList,
                    setBatchTaskCheckAll,
                    setBatchTaskIntermin,
                    setBatchTaskEnable,
                    batchTaskAuth,
                  );
                }}
                checked={batchTaskCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                批量任务
              </Checkbox>
            }
            key="batchTask"
          >
            <CheckboxGroup
              options={batchTaskAuth}
              name="batchTask"
              value={batchTaskList}
              onChange={(list) => {
                onChange(
                  list,
                  setBatchTaskList,
                  setBatchTaskCheckAll,
                  setBatchTaskIntermin,
                  setBatchTaskEnable,
                  batchTaskAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_SYSTEMUSER.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={systemUserIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setSystemUserList,
                    setSystemUserCheckAll,
                    setSystemUserIntermin,
                    setSystemUserEnable,
                    systemUserAuth,
                  );
                }}
                checked={systemUserCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                用户模块
              </Checkbox>
            }
            key="systemUser"
          >
            <CheckboxGroup
              options={systemUserAuth}
              name="systemUser"
              value={systemUserList}
              onChange={(list) => {
                onChange(
                  list,
                  setSystemUserList,
                  setSystemUserCheckAll,
                  setSystemUserIntermin,
                  setSystemUserEnable,
                  systemUserAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
        {OPER_SYSRECORD.length && (
          <CollapsePanel
            className={styles.mypanel}
            header={
              <Checkbox
                indeterminate={sysRecordIntermin}
                onChange={(e) => {
                  onCheckAllChange(
                    e,
                    setSysRecordList,
                    setSysRecordCheckAll,
                    setSysRecordIntermin,
                    setSysRecordEnable,
                    sysRecordAuth,
                  );
                }}
                checked={sysRecordCheckAll}
                onClick={(e) => e.stopPropagation()}
              >
                系统日志
              </Checkbox>
            }
            key="sysRecord"
          >
            <CheckboxGroup
              options={sysRecordAuth}
              name="sysRecord"
              value={sysRecordList}
              onChange={(list) => {
                onChange(
                  list,
                  setSysRecordList,
                  setSysRecordCheckAll,
                  setSysRecordIntermin,
                  setSysRecordEnable,
                  sysRecordAuth,
                );
              }}
            />
          </CollapsePanel>
        )}
      </Collapse>
    </ModalForm>
  );
};
